package com.lframework.starter.web.inner.controller.system;

import com.lframework.starter.web.core.components.resp.InvokeResult;
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
import com.lframework.starter.web.core.components.upload.client.dto.UploadDto;
import com.lframework.starter.web.core.utils.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Api(tags = "公共文件上传")
@Validated
@RestController
@RequestMapping("/system/upload")
public class SysUploadController {


    /**
     * 文件上传
     */
    @ApiOperation("文件上传")
    @PostMapping("/file")
    public InvokeResult<Map<String, String>> upload(@RequestParam("file") MultipartFile file) {
        UploadDto upload = UploadUtil.upload(file);
        Map<String, String> result = new java.util.HashMap<>();
        result.put("url", upload.getUrl());
        result.put("filename", file.getOriginalFilename());
        return InvokeResultBuilder.success(result);
    }

}
